Maximum Depth of Binary Tree

Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

题目大意:计算给定二叉树的深度,非空根节点深度为1

题目难度:Easy

/**
 * Created by gzdaijie on 16/6/7
 */
public class Solution {
    public int maxDepth(TreeNode root) {
        return helper(root, 0);
    }

    private int helper(TreeNode root, int depth) {
        if (root == null) return depth;
        return Math.max(helper(root.left, depth + 1), helper(root.right, depth + 1));
    }
}
gzdaijie            updated 2016-06-07 13:48:36

results matching ""

    No results matching ""